package com.mms.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import net.sf.json.JSONArray;

import com.mms.dao.DepartmentManagementDao;
import com.opensymphony.xwork2.Action;

public class DepartmentAction implements Action {

    
    public String getDepartmentsID() throws IOException {
        DepartmentManagementDao departmentManagementDao=new DepartmentManagementDao();
        departmentManagementDao.getDepartment();
        List<Object[]> departments=departmentManagementDao.getDepartment();
        JSONArray jsonArray = JSONArray.fromObject(departments); 
        System.out.println(jsonArray.toString());
        HttpServletResponse response=ServletActionContext.getResponse();
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        out.print(jsonArray.toString());
        out.flush();
        out.close();
        return SUCCESS;
    }
    
    @Override
    public String execute() throws Exception {
        // TODO Auto-generated method stub
        return null;
    }

}
